const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabbar: {},
    listtwo:[{
      title: '省考备考资料',
      fm: 'https://sd.offcn.com/zg/wximg/2021/guoshengkao/f1.png',
      lists:[]
    }
  ],
    listone:[{
          title: '省考备考资料',
          fm: 'https://sd.offcn.com/zg/wximg/2021/guoshengkao/f1.png',
          lists:[]
        }
      ],
    userInfo: {
      nickName: '您未登录'
    },
    imageList:[
      {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/one.png"},
     {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/two.png"},
     {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/three.png"}
  ],
  winWidth: 0,
  currentTab: 0,
//   list: [
//       {
//     title: '省考备考资料',
//     fm: 'https://sd.offcn.com/zg/wximg/2021/guoshengkao/f1.png',
//     lists: [{
//         name: '五年国考三年模拟申论',
//         sid: 1
//       },
//       {
//         name: '五年国考三年模拟行测',
//         sid: 2
//       },
//       {
//         name: '五年国考三年模拟行测参考答案',
//         sid: 3
//       },
//     ]
//   },
// ],
  },
  topdf(e) {
    var _ = this;
    var phone = wx.getStorageSync('xzlphone')
    if (phone) {
      console.log(e.currentTarget.dataset.sid)
      var sid = e.currentTarget.dataset.sid;
      wx.navigateTo({
        url: '../pdf/pdf?sid=' + sid,
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000
      });
      _.setData({
        login: 1
      })
    }
  },
  getPhoneNumber(e) {
    var _ = this;

    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      _.setData({
        mobile: res.result,
      })
      console.log(res.result)
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 39,
          mobile: res.result,
          areaCode: _.data.area,
          agent: _.data.geneal,
          pageId: _.data.page
        },
        success: res => {
          console.log(res);
        }
      })

      wx.setStorageSync('xzlphone', _.data.mobile)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/biaodan/register?actid=43819&callback=?', //接收url
        data: {
          phone: _.data.mobile,
          fenxiao: _.data.area,
          geneal: _.data.geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)

          _.setData({
            login: 0
          })
        }
      });



    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // app.editTabbar();
    var _ = this;
    // var userInfo = wx.getStorageSync('userInfo')
    // if (userInfo) {
    //   _.setData({
    //     userInfo
    //   })
    // } 
    var phone=wx.getStorageSync('xzlphone')
    if(phone){
          /**
     * 获取用户信息
     */
    wx.getUserInfo({
      success:function(res){
        console.log(res);
        var avatarUrl = 'userInfo.avatarUrl';
        var nickName = 'userInfo.nickName';
        _.setData({
          [avatarUrl]: res.userInfo.avatarUrl,
          [nickName]:res.userInfo.nickName,
        })
      }
    })
    }
    console.log(options);
    _.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      _.setData({
        page: options.page
      })
    }
    //省考资讯
    var zxoneflag = wx.getStorageSync('zxoneflag')
    var zxtwoflag = wx.getStorageSync('zxtwoflag')
    var zxthreeflag = wx.getStorageSync('zxthreeflag')
    var zxfourflag = wx.getStorageSync('zxfourflag')
    var zxfiveflag = wx.getStorageSync('zxfiveflag')
    var zxsixflag = wx.getStorageSync('zxsixflag')
    var zxsevenflag = wx.getStorageSync('zxsevenflag')
    _.setData({
      oneflag:zxoneflag,
      twoflag:zxtwoflag,
      threeflag:zxthreeflag,
      fourflag:zxfourflag,
      fiveflag:zxfiveflag,
      sixflag:zxsixflag,
      sevenflag:zxsevenflag,

    })
    //省考资料
    var shoucangInfo = wx.getStorageSync('shoucangarr')
    var list = wx.getStorageSync('list')
    console.log(list)
    _.setData({
      list:list
    })
    console.log(shoucangInfo)
    for(var i=0;i<shoucangInfo.length;i++)
    {
      if(shoucangInfo[i]==true){
        console.log(_.data.list[0].lists[i])
        _.data.listone[0].lists.push(_.data.list[0].lists[i])
      }
    }
    console.log(_.data.listone)
    _.setData({
      listone:_.data.listone
    })
  },
  link1: function () {
    wx.navigateTo({
      url: '../link/link1/link1'
    })
  },
  link2: function () {
    wx.navigateTo({
      url: '../link/link2/link2'
    })
  },
  link3: function () {
    wx.navigateTo({
      url: '../link/link3/link3'
    })
  },
  link4: function () {
    wx.navigateTo({
      url: '../link/link4/link4'
    })
  },
  link5: function () {
    wx.navigateTo({
      url: '../link/link5/link5'
    })
  },
  link6: function () {
    wx.navigateTo({
      url: '../link/link6/link6'
    })
  },
  link7: function () {
    wx.navigateTo({
      url: '../link/link7/link7'
    })
  },

  // /**
  //  * 生命周期函数--监听页面初次渲染完成
  //  */
  onReady: function () {
    // app.hidetabbar()
  },

  // /**
  //  * 生命周期函数--监听页面显示
  //  */
  onShow: function () {
    var _=this
        //省考资讯
        var zxoneflag = wx.getStorageSync('zxoneflag')
        var zxtwoflag = wx.getStorageSync('zxtwoflag')
        var zxthreeflag = wx.getStorageSync('zxthreeflag')
        var zxfourflag = wx.getStorageSync('zxfourflag')
        var zxfiveflag = wx.getStorageSync('zxfiveflag')
        var zxsixflag = wx.getStorageSync('zxsixflag')
        var zxsevenflag = wx.getStorageSync('zxsevenflag')
        _.setData({
          oneflag:zxoneflag,
          twoflag:zxtwoflag,
          threeflag:zxthreeflag,
          fourflag:zxfourflag,
          fiveflag:zxfiveflag,
          sixflag:zxsixflag,
          sevenflag:zxsevenflag
        })
        //省考资料
        var shoucangInfo = wx.getStorageSync('shoucangarr')
        var list = wx.getStorageSync('list')
        console.log(list)
        _.setData({
          list:list
        })
        console.log(shoucangInfo)
        // 省考资料展示长度
        var chang=0;
       for(var aa=0;aa<shoucangInfo.length;aa++){
         if(shoucangInfo[aa]==true)
         {
           chang=chang+1;
         }
         _.setData({
          chang:chang
         })
       }
       //清空数组
       _.data.listone[0].lists=[]
       _.setData({
        listone:_.data.listone
      })
        for(var i=0;i<shoucangInfo.length;i++)
        {
          if(shoucangInfo[i]==true){
            // console.log(_.data.list[0].lists[i])
            _.data.listone[0].lists.push(_.data.list[0].lists[i])
          }
        }
        
    console.log(_.data.listone[0].lists)
    _.setData({
      listone:_.data.listone
    })
        
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})